package com.rsy.search.controller;


import com.rsy.common.To.es.SkuEsModel;
import com.rsy.common.utils.BizCodeEnume;
import com.rsy.common.utils.R;
import com.rsy.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/search/save")
public class ElasticSaveController {

    @Autowired
    private ProductSaveService productSaveService;
    //上架商品
    @PostMapping("/product")
    public R productStartsUp(@RequestBody List<SkuEsModel> skuEsModels){

        boolean b = false;
        try{
            b = productSaveService.productStatusUp(skuEsModels);
        }catch(Exception e){
            log.error("ElasticSaveController商品上架错误：{}",e);
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }

        if (!b){
            return R.ok();
        }else {
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }

    }
}
